/**
 * @file     plusOne.js
 * @brief    [66. 加一](https://leetcode.cn/problems/plus-one/)
 * @author   Zhu
 * @date     2022-10-15 01:30
 */

/**
 * @param {number[]} digits
 * @return {number[]}
 */
var plusOne = function (digits) {
    let i = digits.length;
    while (i > 0) {
        i--;
        if (digits[i] === 9) {
            digits[i] = 0;
        } else {
            digits[i] += 1;
            return digits;
        }
    }

    return [1, ...digits];
};
